home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / libgutil / pstri.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  17KB  |  716 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    pstri -
  19.  *        Postscript support for drawing lines, and 
  20.  *    shaded triangles.
  21.  *
  22.  *                Paul Haeberli - 1990
  23.  */
  24. #include "vect.h"
  25. #include "stdio.h"
  26. #include "lum.h"
  27.  
  28. static intersect();
  29. static subdivtri();
  30. static outtri();
  31. static plerp();
  32.  
  33. static FILE *outf;
  34.  
  35. #define FULLPAGEYSIZE    (11.0)
  36.  
  37. #define PNTS        (72.0)
  38. #define PAGEXSIZE    (8.0)
  39. #define PAGEYSIZE    (10.5)
  40. #define PAGEASPECT    (PAGEXSIZE/PAGEYSIZE)
  41. #define PAGEMARGIN    (0.25)
  42.  
  43. beginps(theoutf,aspect,x1,x2,y1,y2)
  44. FILE *theoutf;
  45. float aspect, x1, x2, y1, y2;
  46. {
  47.     int i;
  48.     float *fptr;
  49.     float imgxinches, imgyinches;
  50.     float pagexinches, pageyinches, pageaspect;
  51.     float dx, dy;
  52.  
  53.     psoutfile(theoutf);
  54.     fprintf(outf,"%%!PS-Adobe-2.0 EPSF-1.2\n");
  55.     fprintf(outf,"%%%%Creator: IRIS program output\n");
  56.     fprintf(outf,"%%%%BoundingBox: %f %f %f %f\n",PAGEMARGIN*72.0,PAGEMARGIN*72.0,
  57.                     (PAGEXSIZE-PAGEMARGIN)*72.0,(PAGEYSIZE-PAGEMARGIN)*72.0);
  58.     fprintf(outf,"%%%%EndComments\n");
  59.     fprintf(outf,"0.0001 setlinewidth\n");
  60.     fprintf(outf,"1 setlinecap\n");
  61.     fprintf(outf,"1 setlinejoin\n");
  62.     fprintf(outf,"gsave\n");
  63.  
  64.     dx = x2-x1;
  65.     dy = y2-y1;
  66.     if(aspect>1.0) {
  67.     fprintf(outf,"%f %f translate\n",0.0,PNTS*FULLPAGEYSIZE);
  68.     fprintf(outf,"-90.0 rotate\n");
  69.     pagexinches = PAGEYSIZE;
  70.     pageyinches = PAGEXSIZE;
  71.     pageaspect = 1.0/PAGEASPECT;
  72.     } else {
  73.     pagexinches = PAGEXSIZE;
  74.     pageyinches = PAGEYSIZE;
  75.     pageaspect = PAGEASPECT;
  76.     }
  77.     if(aspect<=pageaspect) {
  78.     imgyinches = pageyinches;
  79.     imgxinches = imgyinches*aspect;
  80.     fprintf(outf,"%f %f translate\n",
  81.          PNTS*(PAGEMARGIN+(pagexinches-imgxinches)/2.0),PNTS*PAGEMARGIN);
  82.     } else {
  83.     imgxinches = pagexinches;
  84.     imgyinches = imgxinches/aspect;
  85.     fprintf(outf,"%f %f translate\n",
  86.          PNTS*PAGEMARGIN,PNTS*(PAGEMARGIN+(pageyinches-imgyinches)/2.0));
  87.     }
  88.     fprintf(outf,"%f %f scale\n",PNTS*imgxinches,PNTS*imgyinches);
  89.     fprintf(outf,"%f %f scale\n",1.0/dx,1.0/dy);
  90.     fprintf(outf,"%f %f translate\n",-x1,-y1);
  91.  
  92.     fprintf(outf,"0.0 setgray\n");
  93.  
  94.     fprintf(outf,"/x {\n");
  95.     fprintf(outf,"dup\n");
  96.     fprintf(outf,"dup\n");
  97.     fprintf(outf,"} bind def\n");
  98.  
  99.     fprintf(outf,"/s {\n");
  100.     fprintf(outf,"setlinewidth\n");
  101.     fprintf(outf,"} bind def\n");
  102.  
  103.     fprintf(outf,"/d {\n");
  104.     fprintf(outf,"newpath\n");
  105.     fprintf(outf,"moveto\n");
  106.     fprintf(outf,"lineto\n");
  107.     fprintf(outf,"lineto\n");
  108.     fprintf(outf,"closepath\n");
  109.     fprintf(outf,"stroke\n");
  110.     fprintf(outf,"} bind def\n");
  111.  
  112.     fprintf(outf,"/fq {\n");
  113.     fprintf(outf,"newpath\n");
  114.     fprintf(outf,"moveto\n");
  115.     fprintf(outf,"lineto\n");
  116.     fprintf(outf,"lineto\n");
  117.     fprintf(outf,"lineto\n");
  118.     fprintf(outf,"closepath\n");
  119.     fprintf(outf,"fill\n");
  120.     fprintf(outf,"} bind def\n");
  121.  
  122.     fprintf(outf,"/q {\n");
  123.     fprintf(outf,"newpath\n");
  124.     fprintf(outf,"moveto\n");
  125.     fprintf(outf,"lineto\n");
  126.     fprintf(outf,"lineto\n");
  127.     fprintf(outf,"lineto\n");
  128.     fprintf(outf,"closepath\n");
  129.     fprintf(outf,"stroke\n");
  130.     fprintf(outf,"} bind def\n");
  131.  
  132.     fprintf(outf,"/d3 {\n");
  133.     fprintf(outf,"setgray\n");
  134.     fprintf(outf,"newpath\n");
  135.     fprintf(outf,"moveto\n");
  136.     fprintf(outf,"lineto\n");
  137.     fprintf(outf,"lineto\n");
  138.     fprintf(outf,"closepath\n");
  139.     fprintf(outf,"stroke\n");
  140.     fprintf(outf,"} bind def\n");
  141.  
  142.     fprintf(outf,"/f3 {\n");
  143.     fprintf(outf,"setgray\n");
  144.     fprintf(outf,"newpath\n");
  145.     fprintf(outf,"moveto\n");
  146.     fprintf(outf,"lineto\n");
  147.     fprintf(outf,"lineto\n");
  148.     fprintf(outf,"closepath\n");
  149.     fprintf(outf,"fill\n");
  150.     fprintf(outf,"} bind def\n");
  151.  
  152.     fprintf(outf,"/f4 {\n");
  153.     fprintf(outf,"setgray\n");
  154.     fprintf(outf,"newpath\n");
  155.     fprintf(outf,"moveto\n");
  156.     fprintf(outf,"lineto\n");
  157.     fprintf(outf,"lineto\n");
  158.     fprintf(outf,"lineto\n");
  159.     fprintf(outf,"closepath\n");
  160.     fprintf(outf,"fill\n");
  161.     fprintf(outf,"} bind def\n");
  162.  
  163.     fprintf(outf,"/f5 {\n");
  164.     fprintf(outf,"setgray\n");
  165.     fprintf(outf,"newpath\n");
  166.     fprintf(outf,"moveto\n");
  167.     fprintf(outf,"lineto\n");
  168.     fprintf(outf,"lineto\n");
  169.     fprintf(outf,"lineto\n");
  170.     fprintf(outf,"lineto\n");
  171.     fprintf(outf,"closepath\n");
  172.     fprintf(outf,"fill\n");
  173.     fprintf(outf,"} bind def\n");
  174.  
  175.     fprintf(outf,"/rf3 {\n");
  176.     fprintf(outf,"setrgbcolor\n");
  177.     fprintf(outf,"newpath\n");
  178.     fprintf(outf,"moveto\n");
  179.     fprintf(outf,"lineto\n");
  180.     fprintf(outf,"lineto\n");
  181.     fprintf(outf,"closepath\n");
  182.     fprintf(outf,"fill\n");
  183.     fprintf(outf,"} bind def\n");
  184.  
  185.     fprintf(outf,"/dl {\n");
  186.     fprintf(outf,"newpath\n");
  187.     fprintf(outf,"moveto\n");
  188.     fprintf(outf,"lineto\n");
  189.     fprintf(outf,"stroke\n");
  190.     fprintf(outf,"} bind def\n");
  191.  
  192.     fprintf(outf,"/dist { exch 4 1 roll sub dup mul 3 1 roll sub dup mul\n");
  193.     fprintf(outf,"add } bind def /vdist { 4 index 4 index 11 index 11\n"); 
  194.     fprintf(outf,"index dist } bind def /longrot { vdist 16 6 roll vdist\n"); 
  195.     fprintf(outf,"11 1 roll 10 5 roll 17 -5 roll vdist 17 -1 roll 2 copy\n"); 
  196.     fprintf(outf,"gt { exch 7 -5 roll 12 -5 roll 17 10 roll } if exch pop\n");
  197.     fprintf(outf,"17 -1 roll 2 copy gt { exch 7 -5 roll 12 5 roll } if\n");
  198.     fprintf(outf,"exch pop } bind def /midpoint { { 4 index 10 index add\n");
  199.     fprintf(outf,".5 mul } 11 1 roll 10 index exec 11 index exec 12 index\n");
  200.     fprintf(outf,"exec 13 index exec 15 -1 roll exec } bind def\n");
  201.     fprintf(outf,"/subdivide { 15 -5 roll midpoint 5 copy 25 -5 roll 5\n");
  202.     fprintf(outf,"copy 30 5 roll 25 -5 roll } bind def /trishow { gsave\n");
  203.     fprintf(outf,"15 3 roll moveto 10 3 roll lineto 5 3 roll lineto\n");
  204.     fprintf(outf,"closepath 3 -1 roll 6 -1 roll add 8 -1 roll add 3. div\n");
  205.     fprintf(outf,"3 -1 roll 5 -1 roll add 6 -1 roll add 3. div 5 2 roll\n");
  206.     fprintf(outf,"add add 3. div setrgbcolor fill grestore } bind def\n");
  207.     fprintf(outf,"/subshow { 16 1 roll longrot 16 index gt { subdivide 30\n");
  208.     fprintf(outf,"index subshow 16 -1 roll subshow } { trishow pop }\n");
  209.     fprintf(outf,"ifelse } bind def\n");
  210.  
  211.     fprintf(outf,"/centershow {\n");
  212.     fprintf(outf,"dup\n");
  213.     fprintf(outf,"stringwidth pop -2 div 0 rmoveto\n");
  214.     fprintf(outf,"show\n");
  215.     fprintf(outf,"} def\n");
  216. }
  217.  
  218. endps()
  219. {
  220.     fprintf(outf,"grestore\n");
  221.     fprintf(outf,"showpage\n");
  222. }
  223.  
  224. psoutfile(theoutf)
  225. FILE *theoutf;
  226. {
  227.     outf = theoutf;
  228. }
  229.  
  230. psoutline(outf,p0,p1,p2)
  231. FILE *outf;
  232. vect *p0, *p1, *p2;
  233. {
  234.     fprintf(outf,"%0.4g %0.4g ",p0->x,p0->y);
  235.     fprintf(outf,"%0.4g %0.4g ",p1->x,p1->y);
  236.     fprintf(outf,"%0.4g %0.4g ",p2->x,p2->y);
  237.     fprintf(outf,"1.0 f3\n");
  238.     fprintf(outf,"%0.4g %0.4g ",p0->x,p0->y);
  239.     fprintf(outf,"%0.4g %0.4g ",p1->x,p1->y);
  240.     fprintf(outf,"%0.4g %0.4g ",p2->x,p2->y);
  241.     fprintf(outf,"0.0 d3\n");
  242. }
  243.  
  244. pstriangle(outf,p0,p1,p2,tol)
  245. FILE *outf;
  246. vect *p0, *p1, *p2;
  247. float tol;
  248. {
  249.     fprintf(outf,"%g %g ",p0->x,p0->y);
  250.     fprintf(outf,"%g x\n",p0->z);
  251.     fprintf(outf,"%g %g ",p1->x,p1->y);
  252.     fprintf(outf,"%g x\n",p1->z);
  253.     fprintf(outf,"%g %g ",p2->x,p2->y);
  254.     fprintf(outf,"%g x\n",p2->z);
  255.     fprintf(outf,"%g subshow\n",tol*tol);
  256. }
  257.  
  258. #define TRIGAMMA    (1.0)
  259. #define FLATTOL        (0.00001)
  260.  
  261. cpstriangle(outf,p0,p1,p2,tol)
  262. FILE *outf;
  263. vect *p0, *p1, *p2;
  264. float tol;
  265. {
  266.     vect *v[3], *temp;
  267.     vect points[20], pos;
  268.     int nlevels, npoints;
  269.     float min, max, shade;
  270.     int i, j, didoutput;
  271.  
  272.     v[0] = p0;
  273.     v[1] = p1;
  274.     v[2] = p2;
  275.     if(v[0]->z>v[1]->z) {
  276.     temp = v[0];
  277.     v[0] = v[1];
  278.     v[1] = temp;
  279.     }
  280.     if(v[1]->z>v[2]->z) {
  281.     temp = v[1];
  282.     v[1] = v[2];
  283.     v[2] = temp;
  284.     }
  285.     if(v[0]->z>v[1]->z) {
  286.     temp = v[0];
  287.     v[0] = v[1];
  288.     v[1] = temp;
  289.     }
  290.     nlevels = 1.0/tol;
  291.     if(nlevels>256)
  292.     nlevels = 256;
  293.     if(nlevels<2)
  294.     nlevels = 2;
  295.     didoutput = 0;
  296.  
  297.     max = (float)(1)/nlevels;
  298.     max = pow(max,TRIGAMMA);
  299.     if(v[2]->z<=max) {
  300.     for(j=0; j<3; j++) 
  301.         fprintf(outf,"%0.4g %0.4g ",v[j]->x,v[j]->y);
  302.     fprintf(outf,"%0.4g f%1d\n",0.0,3);
  303.     return;
  304.     }
  305.  
  306.     for(i=0; i<nlevels; i++) {
  307.            min = (float)(i+0)/nlevels;
  308.            max = (float)(i+1)/nlevels;
  309.            shade = i/(nlevels-1.0);
  310.     min = pow(min,TRIGAMMA);
  311.     max = pow(max,TRIGAMMA);
  312.     shade = pow(shade,TRIGAMMA);
  313.     npoints = 0;
  314.  
  315.     for(j=0; j<3; j++) {
  316.         if(intersect(v,2-j,min,&pos)) {
  317.         points[npoints].x = pos.x;
  318.         points[npoints].y = pos.y;
  319.         npoints++;
  320.         }
  321.     }
  322.  
  323.     for(j=0; j<3; j++) {
  324.         if(v[j]->z>=min && v[j]->z<max) {
  325.         points[npoints].x = v[j]->x;
  326.         points[npoints].y = v[j]->y;
  327.         npoints++;
  328.         }
  329.     }
  330.  
  331.     for(j=0; j<3; j++) {
  332.         if(intersect(v,j,max,&pos)) {
  333.         points[npoints].x = pos.x;
  334.         points[npoints].y = pos.y;
  335.         npoints++;
  336.         }
  337.     }
  338.  
  339.     if(npoints>=3 && npoints<=5) {
  340.         didoutput++;
  341.         for(j=0; j<npoints; j++) 
  342.         fprintf(outf,"%0.4g %0.4g ",points[j].x,points[j].y);
  343.         fprintf(outf,"%0.4g f%1d\n",shade,npoints);
  344.     } else if(npoints>0) {
  345.         fprintf(stderr,"badpoints %d\n",npoints);
  346.     }
  347.     }
  348.     if(!didoutput) {
  349.     fprintf(stderr,"no output for tri\n");
  350.     }
  351. }
  352.  
  353. static intersect(v,edge,shade,pos) 
  354. vect *v[3];
  355. int edge;
  356. float shade;
  357. vect *pos;
  358. {
  359.     vect *p0, *p1, *temp;
  360.     float p, del;
  361.  
  362.     p0 = v[edge];
  363.     p1 = v[(edge+1)%3];
  364.     if(p0->z>p1->z) {
  365.     temp = p0;
  366.     p0 = p1;
  367.     p1 = temp;
  368.     }
  369.     if(p1->z<shade)
  370.     return 0;
  371.     if(p0->z>=shade)
  372.     return 0;
  373.     del = (p1->z-p0->z);
  374.     if(del<FLATTOL)
  375.     return 0;
  376.     p = (shade-p0->z)/(p1->z-p0->z);
  377.     pos->x = flerp(p0->x,p1->x,p);
  378.     pos->y = flerp(p0->y,p1->y,p);
  379.     return 1;
  380. }
  381.  
  382. /*
  383.  *    subdiv stuff follows
  384.  *
  385.  */
  386. #define GAMMA        1.0
  387. #define DELGAMMA    0.5
  388.  
  389. static FILE *psout;
  390. static float subdivtol;
  391.  
  392. pssubdivtriangle(outf,p0,p1,p2,c0,c1,c2,tol)
  393. FILE *outf;
  394. vect *p0, *p1, *p2;
  395. vect *c0, *c1, *c2;
  396. float tol;
  397. {
  398.     float x0[5], x1[5], x2[5];
  399.  
  400.     psout = outf;
  401.     subdivtol = tol;
  402.     x0[0] = p0->x;
  403.     x0[1] = p0->y;
  404.     x0[2] = c0->x;
  405.     x0[3] = c0->y;
  406.     x0[4] = c0->z;
  407.     x1[0] = p1->x;
  408.     x1[1] = p1->y;
  409.     x1[2] = c1->x;
  410.     x1[3] = c1->y;
  411.     x1[4] = c1->z;
  412.     x2[0] = p2->x;
  413.     x2[1] = p2->y;
  414.     x2[2] = c2->x;
  415.     x2[3] = c2->y;
  416.     x2[4] = c2->z;
  417.     subdivtri(x0,x1,x2);
  418. }
  419.  
  420. static float cdelta(p0,p1)
  421. float *p0, *p1;
  422. {
  423.     float dr, dg, db;
  424.  
  425.     dr = p0[2] - p1[2];
  426.     if(dr<0)
  427.     dr = -dr;
  428.     dg = p0[3] - p1[3];
  429.     if(dg<0)
  430.     dg = -dg;
  431.     db = p0[4] - p1[4];
  432.     if(db<0)
  433.     db = -db;
  434.     return sqrt(RLUM*dr*dr+GLUM*dg*dg+BLUM*db*db);
  435. }
  436.  
  437. #define NONE    0x0
  438. #define D0    0x1
  439. #define D1    0x2
  440. #define D2    0x4
  441.  
  442. static subdivtri(v0,v1,v2)
  443. float *v0, *v1, *v2;
  444. {
  445.     float d0, d1, d2;
  446.     float i0[5];
  447.     float i1[5];
  448.     float i2[5];
  449.     int code;
  450.  
  451.     d0 = cdelta(v0,v1);
  452.     d1 = cdelta(v1,v2);
  453.     d2 = cdelta(v2,v0);
  454.     code = NONE;
  455.     if(d0>subdivtol)
  456.     code |= D0;
  457.     if(d1>subdivtol)
  458.     code |= D1;
  459.     if(d2>subdivtol)
  460.     code |= D2;
  461.     switch(code) {
  462.     case NONE:
  463.         outtri(v0,v1,v2);
  464.         break;
  465.     case D0:
  466.         plerp(v0,v1,i0);
  467.         subdivtri(v0,i0,v2);
  468.         subdivtri(v2,i0,v1);
  469.         break;
  470.     case D1:
  471.         plerp(v1,v2,i0);
  472.         subdivtri(v1,i0,v0);
  473.         subdivtri(v0,i0,v2);
  474.         break;
  475.     case D2:
  476.         plerp(v2,v0,i0);
  477.         subdivtri(v2,i0,v1);
  478.         subdivtri(v1,i0,v0);
  479.         break;
  480.     case D0|D1:
  481.         plerp(v0,v1,i0);
  482.         plerp(v1,v2,i1);
  483.         subdivtri(v0,i0,v2);
  484.         subdivtri(v2,i0,i1);
  485.         subdivtri(v1,i1,i0);
  486.         break;
  487.     case D1|D2:
  488.         plerp(v1,v2,i0);
  489.         plerp(v2,v0,i1);
  490.         subdivtri(v1,i0,v0);
  491.         subdivtri(v0,i0,i1);
  492.         subdivtri(v2,i1,i0);
  493.         break;
  494.     case D2|D0:
  495.         plerp(v2,v0,i0);
  496.         plerp(v0,v1,i1);
  497.         subdivtri(v2,i0,v1);
  498.         subdivtri(v1,i0,i1);
  499.         subdivtri(v0,i1,i0);
  500.         break;
  501.     case D2|D1|D0:
  502.         plerp(v0,v1,i0);
  503.         plerp(v1,v2,i1);
  504.         plerp(v2,v0,i2);
  505.         subdivtri(v0,i0,i2);
  506.         subdivtri(v1,i1,i0);
  507.         subdivtri(v2,i2,i1);
  508.         subdivtri(i0,i1,i2);
  509.         break;
  510.     }
  511. }
  512.  
  513. static plerp(v0,v1,l)
  514. float *v0, *v1, *l;
  515. {
  516.     l[0] = (v0[0]+v1[0])/2.0;
  517.     l[1] = (v0[1]+v1[1])/2.0;
  518.     l[2] = (v0[2]+v1[2])/2.0;
  519.     l[3] = (v0[3]+v1[3])/2.0;
  520.     l[4] = (v0[4]+v1[4])/2.0;
  521. }
  522.  
  523. static outtri(v0,v1,v2)
  524. float *v0, *v1, *v2;
  525. {
  526.     float ar, ag, ab;
  527.  
  528.     fprintf(psout,"%g %g ",v0[0],v0[1]);
  529.     fprintf(psout,"%g %g ",v1[0],v1[1]);
  530.     fprintf(psout,"%g %g ",v2[0],v2[1]);
  531.     ar = (v0[2]+v1[2]+v2[2])/3.0;
  532.     ag = (v0[3]+v1[3]+v2[3])/3.0;
  533.     ab = (v0[4]+v1[4]+v2[4])/3.0;
  534.     fprintf(psout,"%g %g %g rf3\n",ar,ag,ab);
  535. }
  536.  
  537. pslinewidth(width)
  538. float width;
  539. {
  540.      fprintf(outf,"%g s\n",width);
  541. }
  542.  
  543. psline(outf,v0,v1)
  544. FILE *outf;
  545. float *v0, *v1;
  546. {
  547.      fprintf(outf,"%g %g %g %g dl\n",v0[0],v0[1],v1[0],v1[1]);
  548. }
  549.  
  550. psgrey(g)
  551. float g;
  552. {
  553.     fprintf(outf,"%g setgray\n",g);
  554. }
  555.  
  556. psrgb(r,g,b)
  557. float r, g, b;
  558. {
  559.     fprintf(outf,"%g %g %g setrgbcolor\n",r,g,b);
  560. }
  561.  
  562. pscmyk(c,m,y,k)
  563. float c, m, y, k;
  564. {
  565.     fprintf(outf,"%g %g %g %g setcmykcolor\n",c,m,y,k);
  566. }
  567.  
  568. pssetfont(name,size)
  569. char *name;
  570. float size;
  571. {
  572.     fprintf(outf,"/%s findfont\n",name);
  573.     fprintf(outf,"%f scalefont setfont\n",size);
  574. }
  575.  
  576. psshow(str)
  577. char *str;
  578. {
  579.     fprintf(outf,"(%s) show\n",str);
  580. }
  581.  
  582. pscentershow(str)
  583. char *str;
  584. {
  585.     fprintf(outf,"(%s) centershow\n",str);
  586. }
  587.  
  588. psnewpath()
  589. {
  590.     fprintf(outf,"newpath\n");
  591. }
  592.  
  593. psmoveto(x,y)
  594. float x, y;
  595. {
  596.     fprintf(outf,"%f %f moveto\n",x,y);
  597. }
  598.  
  599. psmovetoi(x,y)
  600. int x, y;
  601. {
  602.     fprintf(outf,"%d %d moveto\n",x,y);
  603. }
  604.  
  605. pslineto(x,y)
  606. float x, y;
  607. {
  608.     fprintf(outf,"%f %f lineto\n",x,y);
  609. }
  610.  
  611. pslinetoi(x,y)
  612. int x, y;
  613. {
  614.     fprintf(outf,"%d %d lineto\n",x,y);
  615. }
  616.  
  617. psclosepath()
  618. {
  619.     fprintf(outf,"closepath\n");
  620. }
  621.  
  622. psstroke()
  623. {
  624.     fprintf(outf,"stroke\n");
  625. }
  626.  
  627. psfill()
  628. {
  629.     fprintf(outf,"fill\n");
  630. }
  631.  
  632. psrect(x1,y1,x2,y2)
  633. float x1, y1, x2, y2;
  634. {
  635.     fprintf(outf,"%f %f %f %f\n",x1,y1,x2,y1);
  636.     fprintf(outf,"%f %f %f %f q\n",x2,y2,x1,y2);
  637. }
  638.  
  639. psrectf(x1,y1,x2,y2)
  640. float x1, y1, x2, y2;
  641. {
  642.     fprintf(outf,"%f %f %f %f\n",x1,y1,x2,y1);
  643.     fprintf(outf,"%f %f %f %f fq\n",x2,y2,x1,y2);
  644. }
  645.  
  646. pstranslate(x,y)
  647. float x, y;
  648. {
  649.     fprintf(outf,"%f %f translate\n",x,y);
  650. }
  651.  
  652. psscale(x,y)
  653. float x, y;
  654. {
  655.     fprintf(outf,"%f %f scale\n",x,y);
  656. }
  657.  
  658. psrotate(r)
  659. float r;
  660. {
  661.     fprintf(outf,"%f rotate\n",r);
  662. }
  663.  
  664. psshowpage()
  665. {
  666.     fprintf(outf,"showpage\n");
  667. }
  668.  
  669. psgsave()
  670. {
  671.     fprintf(outf,"gsave\n");
  672. }
  673.  
  674. psgrestore()
  675. {
  676.     fprintf(outf,"grestore\n");
  677. }
  678.  
  679.  
  680. /*
  681.  *    this correction table is for our QMS laser printer.
  682.  *
  683.  */
  684. psprintcortab()
  685. {
  686.     fprintf(outf,"/PHtransfer {\n");
  687.     fprintf(outf,"%%                                   .\n");
  688.     fprintf(outf,"%% cortab for hypval 0.509652 powval 1.476834 iscale 1.000000\n");
  689.     fprintf(outf,"%%                                   .\n");
  690.     fprintf(outf,"    <00010103040507080a0c0d0f11131517\n");
  691.     fprintf(outf,"     191a1c1e20222426282a2c2e30323436\n");
  692.     fprintf(outf,"     37393b3d3f41434446484a4b4d4f5152\n");
  693.     fprintf(outf,"     545657595b5c5e606163646667696a6c\n");
  694.     fprintf(outf,"     6d6f707273747677797a7b7d7e7f8182\n");
  695.     fprintf(outf,"     8384868788898b8c8d8e8f9192939495\n");
  696.     fprintf(outf,"     9697999a9b9c9d9e9fa0a1a2a3a4a5a6\n");
  697.     fprintf(outf,"     a7a8a9aaabacadaeafb0b0b1b2b3b4b5\n");
  698.     fprintf(outf,"     b6b7b7b8b9babbbcbcbdbebfc0c0c1c2\n");
  699.     fprintf(outf,"     c3c4c4c5c6c7c7c8c9c9cacbcccccdce\n");
  700.     fprintf(outf,"     cecfd0d0d1d2d2d3d4d4d5d6d6d7d7d8\n");
  701.     fprintf(outf,"     d9d9dadadbdcdcdddddedfdfe0e0e1e1\n");
  702.     fprintf(outf,"     e2e3e3e4e4e5e5e6e6e7e7e8e8e9e9ea\n");
  703.     fprintf(outf,"     eaebebececededeeeeefeff0f0f1f1f2\n");
  704.     fprintf(outf,"     f2f2f3f3f4f4f5f5f6f6f6f7f7f8f8f9\n");
  705.     fprintf(outf,"     f9f9fafafbfbfbfcfcfdfdfdfefeffff\n");
  706.     fprintf(outf,"     >\n");
  707.     fprintf(outf,"    %% 256 steps\n");
  708.     fprintf(outf,"    exch /PHval exch def\n");
  709.     fprintf(outf,"    PHval 0.0 lt {/PHval 0.0 def} if\n");
  710.     fprintf(outf,"    PHval 1.0 gt {/PHval 1.0 def} if\n");
  711.     fprintf(outf,"    PHval 255.0 mul 0.5 add cvi get\n");
  712.     fprintf(outf,"    255.0 div\n");
  713.     fprintf(outf,"} bind def\n");
  714.     fprintf(outf,"{ PHtransfer } settransfer\n");
  715. }
  716.